import { NzMessageService } from 'ng-zorro-antd/message';
import { NzModalRef } from 'ng-zorro-antd/modal';
import { Component, OnInit } from '@angular/core';
import { NzFormatEmitEvent } from 'ng-zorro-antd';
import { goodsItems } from '../../../../assets/goodsItems.json';

@Component({
  selector: 'zepride-goods-modal',
  templateUrl: './goods-modal.component.html',
  styleUrls: ['./goods-modal.component.less']
})
export class GoodsModalComponent implements OnInit {
  searchValue: string;
  nodes = goodsItems;
  selectedNodeItem;
  radioValue;

  constructor(
    private modalRef: NzModalRef,
    private msg: NzMessageService
  ) {
  }

  ngOnInit(): void {
  }

  ok() {
    if (!this.selectedNodeItem) {
      this.msg.error('当前未选择品目！');
      return;
    }
    this.modalRef.close(this.selectedNodeItem);
  }
  cancel() {
    this.modalRef.close();
  }

  nzEvent(event: NzFormatEmitEvent): void {
    if (event.node.isLeaf) {
      this.selectedNodeItem = event.node.origin;
    }
  }

  selecteNode(node) {
    this.selectedNodeItem = node;
  }

}

interface TreeNode {
  name: string;
  children?: TreeNode[];
}
